package project2;
/* Alice Robinson and Holly Beach
 * TCSS491 - Winter 2012*/

import java.io.Serializable;

import javax.media.opengl.*;

/**A PCircle is a PhysicsObject with a Circle Renderable object.
 * It has 4 constructors:  One takes the size(radius),
 * One takes the size and pickable boolean
 * One takes the the size, red, green, and blue colors
 * and one takes the size, pickable boolean, red, green, and blue colors */
public class PCircle extends PhysicsObject implements Serializable {
	private static final long serialVersionUID = 5289147373297520854L;

	private class Renderable extends SceneGraphNode implements Serializable {
		private static final long serialVersionUID = -4718473711646099404L;
		private static final int POINTS = 20;	
		
		public Renderable() {
			this(true); //pickable defaults to true
		}
		public Renderable(boolean pickable) {
			super(pickable);
			scale = radius;
		}
		
		public void renderGeometry(GLAutoDrawable drawable) {
			GL2 gl = drawable.getGL().getGL2();		
			gl.glColor3f(red,green,blue);
			gl.glBegin(GL.GL_TRIANGLE_FAN);
			gl.glVertex2f(0, 0);
			for (int i = 0; i <= POINTS; i++) {
				double radians =  2* Math.PI * i / POINTS;
				gl.glVertex2d(Math.cos(radians), Math.sin(radians));
			}
			gl.glEnd();
		}
	}
	public PCircle(){
		renderable = new Renderable(true);
		renderable.scale = .5f;
		this.radius = .5f;
	}

	public PCircle(float radius) {
		renderable = new Renderable(true);
		renderable.scale = radius;
		this.radius = radius;
	}
	public PCircle(float radius, boolean pickable, float red, float green, float blue) {
		this.radius = radius;
		renderable = new Renderable(pickable);
		renderable.red = red;
		renderable.green = green;
		renderable.blue = blue;
	}
}